import { legacy_createStore, applyMiddleware } from 'redux'
import logger from 'redux-logger'
import thunk from 'redux-thunk'
import { ALLSTATE, ACTIONTYPE } from '../type/store.d'
const initialState = {
    swiperlist: [],
    gridlist: [],
    list: [],
    tablist: [],
    children: [],
}

const reducer = (state: ALLSTATE = initialState, { type, payload }: ACTIONTYPE) => {
    switch (type) {

        case 'SETSWIPER':
            state.swiperlist = payload
            return { ...state }

        case 'SETGRID':
            state.gridlist = payload
            return { ...state }

        case 'SETLIST':
            state.list = payload
            return { ...state }

        case 'SETTAB':
            state.tablist = payload
            state.children = payload[0].info
            return { ...state }

        case 'SETINDEX':
            state.children = state.tablist[payload].info
            return { ...state }

        default:
            return state
    }
}

const store = legacy_createStore(reducer, applyMiddleware(logger, thunk))

export default store
